package com.bnyy.medicalHousekeeper.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bnyy.medicalHousekeeper.R;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;

public abstract class BaseSwipeDeleteAdapter extends RecyclerView.Adapter {

    public Context mContext;
    public LayoutInflater inflater;

    public BaseSwipeDeleteAdapter(Context context) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }

    public abstract int getContentLayout();

    public abstract boolean isFullDeleteButton();

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View root = inflater.inflate(R.layout.item_base_swipe_delete, parent, false);
        FrameLayout frameLayout = root.findViewById(R.id.fl_container);
        FrameLayout flDeleteRoot = root.findViewById(R.id.fl_delete_root);
        View view = inflater.inflate(getContentLayout(), root.findViewById(R.id.fl_container), false);
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            if (!isFullDeleteButton()) {
                flDeleteRoot.setPadding(0, marginLayoutParams.topMargin, marginLayoutParams.rightMargin, marginLayoutParams.bottomMargin);
                root.findViewById(R.id.tv_delete).setBackgroundResource(R.drawable.shape_bg_corner_red);
            }
        }
        frameLayout.addView(view);

        return new ViewHolder(root);
    }

    public abstract void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position);

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public View delete;
        public View itemView;
        public View flContent;
        public SwipeMenuLayout swipeMenuLayout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.itemView = itemView;
            delete = itemView.findViewById(R.id.tv_delete);
            flContent = itemView.findViewById(R.id.fl_container);
            swipeMenuLayout = itemView.findViewById(R.id.swipe_menu_layout);
        }
    }
}




















